{{csrf_field()}}
<div class="layui-form-item">
    <label for="" class="layui-form-label">名称：</label>
    <div class="layui-input-inline">
        <input type="text" name="name" value="{{ $dao->name ?? old('name') }}" placeholder="请输入名称" class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">品牌：</label>
    <div class="layui-input-inline">
        <select name="brand_id" id="brand_id" lay-filter="brand_id">
            <option value="">请选择品牌</option>
        </select>
    </div>
    <label for="" class="layui-form-label">品牌型号：</label>
    <div class="layui-input-inline">
        <select name="brand_model_id" id="brand_model_id" lay-filter="brand_model_id">
            <option value="">请选择品牌型号</option>
        </select>
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">年份：</label>
    <div class="layui-input-inline">
        <select name="year">
            <option value="">请选择年份</option>
            @foreach(\Illuminate\Support\Facades\Config::get('constant.year') as $key => $val)
                @if(isset($dao->year) && $dao->year == $key)
                    <option value="{{$key}}" selected >{{$val}}</option>
                @else
                    <option value="{{$key}}">{{$val}}</option>
                @endif
            @endforeach
        </select>

    </div>
    <label for="" class="layui-form-label">产品类型：</label>
    <div class="layui-input-inline">
        <select name="product_model">
            <option value="">请选择产品类型</option>
            @foreach(\Illuminate\Support\Facades\Config::get('constant.product_model') as $key => $val)
                @if(isset($dao->product_model) && $dao->product_model == $key)
                    <option value="{{$key}}" selected >{{$val}}</option>
                @else
                    <option value="{{$key}}">{{$val}}</option>
                @endif
            @endforeach
        </select>
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">图片：</label>
    <div class="layui-input-inline">
        <div class="layui-img" style="display: none" id="cover-show">
            <input type="hidden" value="{{$dao->cover??''}}" name="cover" id="cover">
            <img src="{{$dao->cover??''}}" id="cover-img" class="layui-img-content" alt="">
            <div class="layui-img-delete" id="cover-del">
                <i class="layui-icon layui-icon-delete"></i>
            </div>
        </div>
        <div class="layui-img" id="cover-upload">
            <i class="layui-icon layui-icon-add-1 layui-img-icon"></i>
        </div>
    </div>
    <label for="" class="layui-form-label">备注：</label>
    <div class="layui-input-inline">
        <textarea name="note" class="layui-textarea">{{$dao->note ?? ''}}</textarea>
    </div>
</div>


@foreach($productItem as $key => $val)
    <input type="hidden" name="item[{{$val->id}}][id]" value="{{$val->id}}" class="layui-input" >
    @if(isset($dao->itemIds) && in_array($val->id,$dao->itemIds))
        <div class="layui-form-item">
            <label for="" class="layui-form-label">{{$val->name}}：</label>
            <div class="layui-input-inline">
                <input type="text" name="item[{{$val->id}}][amount]" value="{{$dao->itemData[$val->id] ?? ''}}" placeholder="请输入金额" class="layui-input" >
            </div>
        </div>
    @else
        <div class="layui-form-item">
            <label for="" class="layui-form-label">{{$val->name}}：</label>
            <div class="layui-input-inline">
                <input type="text" name="item[{{$val->id}}][amount]" value="" placeholder="请输入金额" class="layui-input" >
            </div>
        </div>
    @endif
@endforeach



<div class="layui-form-item">
    <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="postForm">确 认</button>
        <a  class="layui-btn" href="javascript:void(0)" id="close" >关 闭</a>
    </div>
</div>



<style>
    .layui-img-list {
        display: flex;
    }
    .layui-img-list div {
        margin-right: 10px;
    }
    .layui-img{
        width: 8em;
        height: 8em;
        border:1px #e8e8e8 solid;
        padding: .5em;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }
    .layui-img-content{
        width: auto;
        height: auto;
        max-width: 8em;
        max-height: 8em;
    }
    .layui-img-delete{
        position: absolute;
        top:3px;
        right:5px;
        background-color: rgba(0,0,0,0.5);
        color: #fff;
        width: 20px;
        height: 20px;
        border-radius: 10px;
        line-height: 20px;
        text-align: center;
        cursor: pointer;
    }
    .layui-img-delete:hover{
        width: 22px;
        height: 22px;
        border-radius: 11px;
        line-height: 22px;
        top: 2px;
        right: 4px;
    }

    .layui-img-icon{
        font-size:40px;
    }
</style>